package com.hyh.shiyanshiguanli.controller;
import com.hyh.shiyanshiguanli.constant.MessageConstant;
import com.hyh.shiyanshiguanli.domain.dto.*;
import com.hyh.shiyanshiguanli.domain.entity.Classify;
import com.hyh.shiyanshiguanli.domain.entity.LibInformation;
import com.hyh.shiyanshiguanli.domain.entity.LibManager;
import com.hyh.shiyanshiguanli.domain.entity.PublicInformation;
import com.hyh.shiyanshiguanli.domain.result.PageResult;
import com.hyh.shiyanshiguanli.domain.result.Result;
import com.hyh.shiyanshiguanli.service.LibInformationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author hyh
 * @version 1.0
 */
@RestController
@Slf4j
@RequestMapping("/libInfo")
public class libInformation {

    @Autowired
    LibInformationService libInformationService;

    @GetMapping("/page")
    public Result<PageResult> page(PageDTO pageDTO){
        log.info("实验室的分页查询{}",pageDTO.getMessage());
        PageResult result = libInformationService.page(pageDTO);
        return Result.success(result);
    }

    @GetMapping("/{id}")
    public Result<LibInformation> selectById(@PathVariable Integer id){
        log.info("根据id查询LibInformation{}",id);
        LibInformation libInformation = libInformationService.selectById(id);
        return Result.success(libInformation);
    }

    @GetMapping("/classify")
    public Result<List> selectClassify(){
        log.info("查询所有实验室分类");
        List<Classify> classifies = libInformationService.selectClassify();
        return Result.success(classifies);
    }

    @PutMapping("/update")
    public Result updateById(@RequestBody LibInformationUpdateDTO libInformationUpdateDTO){
        log.info("更新实验实验室数据id为{}",libInformationUpdateDTO.getId());
        libInformationService.updateById(libInformationUpdateDTO);
        return Result.success();
    }

    @PostMapping("/add")
    public Result addPublicInformation(@RequestBody LibInformationAddDTO libInformationAddDTO){
        log.info("添加libInformation{}",libInformationAddDTO);
        libInformationService.add(libInformationAddDTO);
        return Result.success();
    }

    @DeleteMapping("/deleteById")
    public Result deleteById(Integer id){
        log.info("删除id为{}的classify",id);
        int delete = libInformationService.deleteById(id);
        if (delete == MessageConstant.SUCCESS){
            return Result.success();
        }
        else{
            return Result.error("不能删除");
        }

    }
}
